'use strict';

const config = require('../config');

exports.list = function * (next) {
  let qs = this.query;
  // console.log('qs:', qs)
  if (!qs) yield next;
  const Options = [
    'limit',
    'offset',
    'skip',
    'sort'
  ];
  let query = {};
  let options = {};
  for (let q in qs) {
    if (Options.some((x) => x === q)) {
      q === 'offset'
        ? options.skip = qs[q]
        : options[q] = qs[q];
    } else {
      query[q] = qs[q];
    }
  }
  this.query = {};
  let limit = options.limit || config.app.limit;
  options.limit = parseInt(limit);
  options.skip = options.skip ? parseInt(options.skip) * options.limit : 0;
  this.query.options = options;
  this.query.query = query;
  // console.log('new query:', this.query)
  yield next;
};

exports.group = function * (next) {};
